<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../../include.inc.jsp"%>
<div class="col-lg-12">
	<div class="widget-box transparent" id="divSearch" hidden="true" >
		<div class="widget-header widget-header-large">
			<h4 class="widget-title">搜索</h4>
		</div>
		<div class="widget-body">
			<div class="widget-main">
				<form  name="frmSearch" id="frmSearch" target="_self"  class="form-inline searchCondition">
                    <!-- 数据权限 begion-->
                    <c:if test="${organizationId != 1}"><input type="hidden" name="search_EQ_organization.id" value="${organizationId }"/></c:if>
                    <!-- 数据权限 end-->
					<label>
						手机号:&nbsp;<input name="search_LIKE_user.mobile" class="form-control" placeholder="请输入手机号" type="text">
					</label>
					<label>
						职工名称:&nbsp;<input name="search_LIKE_name" class="form-control" placeholder="请输入职工名称" type="text">
					</label>
					<button id="btnSearch" type="button" class="btn btn-primary btn-sm form-control">
						<i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
					</button>
				</form>
			</div>
		</div>
	</div>
	<div id="tbWidget" class="widget-box transparent ui-sortable-handle">
		<div class="widget-header widget-header-large no-padding">
			<div class="widget-title smaller">
				<div id="toolbar" class="btn-group btn-corner">
				    <so:hasPermission name="Order:employee:add">
				    	<button id="add" class="btn btn-pink" type="button"><span class="glyphicon glyphicon-plus"></span>&nbsp;新增</button>
				    </so:hasPermission>
				    <so:hasPermission name="Order:employee:modify">
				    	<button id="edt" class="btn btn-success" type="button"><span class="glyphicon glyphicon-edit"></span>&nbsp;编辑</button>
				    </so:hasPermission>
				    <so:hasPermission name="Order:employee:remove">
				    	<button id="del" class="btn btn-danger" type="button"><span class="glyphicon glyphicon-remove"></span>&nbsp;删除</button>
				    </so:hasPermission>
				    <so:hasPermission name="Order:employee:search">
				    	<button id="search" class="btn btn-primary" type="button"><span class="glyphicon glyphicon-search"></span>&nbsp;查询</button>
				    </so:hasPermission>
				</div>
			</div>
			<div class="widget-toolbar">
			   <a data-action="reload" class="green2 bigger-120" href="#"><i class="ace-icon fa fa-refresh"></i></a>
			   <a data-action="fullscreen" class="blue2 bigger-120" href="#"><i class="ace-icon fa fa-arrows-alt"></i></a>
			 </div>
		</div>
		<div class="widget-body">
			<div class="widget-main no-padding">
				<table id="table-data"
					data-classes="table table-striped table-hover" 
					   data-pagination="true"
				       data-id-field="id"
				       data-unique-id="id"
				       data-sort-name="id"
				       data-sort-order="asc">
				</table>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
var scripts = [];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	var ajaxListUrl = contextPath + '/manage/ordering/employee/list';
	var ajaxAddUrl = contextPath + '/manage/ordering/employee/add';
	var ajaxEdtUrl = contextPath + '/manage/ordering/employee/edit';
	var ajaxDelUrl = contextPath + '/manage/ordering/employee/remove';
	
    //输出字典js变量
    <x:dictData dictCode="Sex_Type" var="sexs">
    <x:jsonArray varName="sexs" keyName="code" valName="name" items="${sexs}" ></x:jsonArray>
    </x:dictData>
    
    <x:dictData dictCode="Is_Recommend" var="isRecommends">
    <x:jsonArray varName="isRecommends" keyName="code" valName="name" items="${isRecommends}" ></x:jsonArray>
    </x:dictData>
    
	var columns = [ {
		field : 'state',
		checkbox : true,
		title : "选择"
	}, {
		field : 'user.mobile',
		sortable : false,
		title : "手机号"
	}, {
		field : 'department.cardNo',
		sortable : false,
		title : "智能卡号"
	}, {
		field : 'name',
		sortable : false,
		title : "职工姓名"
	}, {
		field : 'sex',
		sortable : false,
		title : "性别",
        formatter: function(value, row, index){
            var show = value;
            $.each(sexs, function() {
                if (this.code == value) {
                    show = this.name;
                }
            });
            return show;
        }
	}, {
		field : 'birthday',
		sortable : false,
		title : "生日",
		formatter:function(value,row,index){
			var show = value;
			if(show != null){
				show = show.split(" ")[0];
			}
			return show;
		}
	}, {
		field : 'postJob',
		sortable : false,
		title : "职务"
	}, {
		field : 'address',
		sortable : false,
		title : "家庭住址"
	}, {
// 		field : 'remark',
// 		sortable : false,
// 		title : "职工介绍"
// 	}, {
		field : 'isRecommend',
		sortable : false,
		title : "是否推荐",
        formatter: function(value, row, index){
            var show = value;
            $.each(isRecommends, function() {
                if (this.code == value) {
                    show = this.name;
                }
            });
            return show;
        }
	}, {
		field : 'department.name',
		sortable : false,
		title : "所属科室"
	}, {
        field : 'department.hospital.name',
        sortable : false,
        title : "所属医院"
    }
	];

	jQuery(function($) {
        initTable('table-data', columns, ajaxListUrl, 'frmSearch');
        
		$('#search').on('click', function() {
			$('#divSearch').slideToggle("slow");
		});

		// 搜索域控制
		$('#frmSearch').find('#btnSearch').on('click', function() {
			$('#table-data').bootstrapTable('selectPage', 1);
		});

		$('#tbWidget').on('reload.ace.widget', function(ev) {
			$('#table-data').bootstrapTable('refresh', { silent : true });
		});

		$('#add').on('click', function(e) {
			showAddDlg("新增", ajaxAddUrl, "formDlg", function() {
				$('#table-data').bootstrapTable('refresh', { silent : true });
			});
		});

		$('#edt').on('click', function(e) {
			showEdtDlg("编辑", ajaxEdtUrl, "table-data", "formDlg", function() {
				$('#table-data').bootstrapTable('refresh', { silent : true });
			})
		});

		$('#del').on('click', function(e) {
			doDelete(ajaxDelUrl, "table-data", function() {
			});
		});
		
	});
});
function showAddDlg(title, ajaxUrl, formId, btnCall){
    BootstrapDialog.show({
        type: BootstrapDialog.TYPE_DEFAULT,
        closable:false,
        draggable: true,
        title: title,
        message: $('<div></div>').load(ajaxUrl),
        buttons: [{
            id: 'btn-OK',   
            icon: 'glyphicon glyphicon-remove',
            label: '关闭',
            cssClass: 'btn-default', 
            autospin: false,
            action: function(dialogRef){
                dialogRef.close();
            }
        }, {
            id: 'btn-OK', 
            icon: 'glyphicon glyphicon-check',
            label: '确认', 
            cssClass: 'btn-primary', 
            autospin: false, 
            action: function(dialogRef){
                if($('#' + formId).valid()){
                    saveOrUpdateFileAndForm(formId,contextPath+'/manage/ordering/employee/add',dialogRef,successCallBack);
                }
            }
         }]
    });
}

function showEdtDlg(title, ajaxUrl, tableId, formId, btnCall){
    var selections = $('#' + tableId).bootstrapTable("getSelections");
    if (selections !== undefined && selections !== null) {
        if (selections.length === 1) {
            var id = selections[0].id;
            var formUrl = ajaxUrl + "/" + id;
            BootstrapDialog.show({
                    type: BootstrapDialog.TYPE_DEFAULT,
                    closable:false,
                    draggable: true,
                    title: title,
                    message: $('<div></div>').load(formUrl),
                    buttons: [{
                        id: 'btn-OK',   
                        icon: 'glyphicon glyphicon-remove',
                        label: '关闭',
                        cssClass: 'btn-default', 
                        autospin: false,
                        action: function(dialogRef){
                            dialogRef.close();
                        }
                    }, {
                        id: 'btn-OK', 
                        icon: 'glyphicon glyphicon-check',
                        label: '确认', 
                        cssClass: 'btn-primary', 
                        autospin: false, 
                        action: function(dialogRef){
                            if($('#' + formId).valid()){
                                saveOrUpdateFileAndForm(formId,contextPath+'/manage/ordering/employee/edit',dialogRef,successCallBack);
                            }
                        }
                    }]
                });
        } else {
            CmMsg.warn("请选择一行数据记录进行操作.", -1);
        }
    } else {
        CmMsg.warn("没有选中任何数据记录,无法进行操作.", -1);
    }
}
function successCallBack(data,dialogRef){
    if(data.status == 'OK'){
        dialogRef.close();
        $("#table-data").bootstrapTable('refresh');//刷新表单
        CmMsg.success(data.message, -1);
    } else if(data.status == 'ERROR'){
        CmMsg.error(data.message, -1);
    } else if (data.status == 'TIMEOUT'){
        CmMsg.error(data.message, -1);
    } else {
        CmMsg.error("保存失败或其他错误", -1);
    }
}
</script>